angular.module("crawlerApp").factory("menuService", function ($q,$rootScope) {

    var menu = [
        {
            "code": "basic",
            "basic_menu": [{
                "code": "singleTask",
                "parent": "basic",
                "name": "配置规则",
                url:"/singleTask",
                params:{config:null},
                templateUrl:"html/simple/singleTask.html",
                controller:"singleTaskCtrl"
            },

                {
                    "code": "quartz",
                    "parent": "basic",
                    "name": "任务管理",
                    url:"/quartzTask",
                    params:{config:null},
                    templateUrl:"html/simple/quartzTask.html",
                    controller:"quartzTaskCtrl"
                },


                {
                    "code": "result",
                    "parent": "basic",
                    "name": "结果查看",
                    url:"/taskResult",
                    params:{config:null},
                    templateUrl:"html/simple/taskResult.html",
                    controller:"taskResultCtrl"
                }
                ,
                {
                    "code": "logger",
                    "parent": "basic",
                    params:{config:null},
                    name:"日志查看",
                    url:"/logger",
                    templateUrl:"html/logger/logger-analysis.html",
                    controller:"loggerCtrl",
                }



            ]
        },
        {
            "code": "simple",
            "basic_menu": [{
                "code": "simpleConfig",
                "parent": "simple",
                "name": "首页",
                url:"/simple",
                templateUrl:"html/simple/simple-config.html",
                controller:"simpleConfigCtrl",
            },
                {
                    "code": "dataType",
                    "parent": "simple",
                   // "name": "定义数据格式",
                   // url:"/dataFormat",
                    params:{config:null},
                  //  templateUrl:"html/task/dataFormat.html",
                   // controller:"dataFormatCtrl",
                    name:"创建索引",
                    url:"/dataType",
                    params:{config:null},
                    templateUrl:"html/task/dataType.html",
                    controller:"dataTypeCtrl",
                    //label:"创建索引"
                }]

        }]
    ;
    var authorizedMenuInfo = {
        "initMenu": []
    };

    function getBasicMenu(code) {

        var deffer = $q.defer();
        angular.forEach(menu, function (item) {
            if (item.code === code) {
                authorizedMenuInfo.initMenu = angular.copy(item.basic_menu);
                return -1;
            }
        });
        deffer.resolve(authorizedMenuInfo);
        return deffer.promise;
    }

    return {
        getBasicMenu: getBasicMenu
    };
});